﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using SD.Database.Classes;
using DBAccess;

namespace SD.Database
{
    public partial class StoredProcedures
    {
        private static string MsSqlCreateTableSystems = @"CREATE TABLE [dbo].[Systems](
	                [SystemID] [int] IDENTITY(1,1) NOT NULL,
	                [SystemName] [nvarchar](50) COLLATE Polish_CI_AS NOT NULL,
	                [X] [int] NOT NULL,
	                [Y] [int] NOT NULL)";
        private static string MySqlCreateTableSystems = @"CREATE TABLE systems(
	            SystemID int Auto_Increment Primary Key NOT NULL,
	            SystemName varchar(50)  NOT NULL,
	            X int NOT NULL,
	            Y int NOT NULL
                ) ;";

        public static void RestartGame()
        {
            DAL dal = DAL.GetInstance();
            dal.DeleteData("Delete from news");
            dal.DeleteData("Delete from fleets");
            dal.DeleteData("Delete from battles");
            dal.DeleteData("Delete from Planets");
            dal.DeleteData("Delete  from AllianceMembers");
            dal.DeleteData("Delete  from Alliances");
            dal.DeleteData("Delete  from Artifacts");
            dal.DeleteData("Delete  from Players Where PlayerId > 1");
            dal.DeleteData("Delete  from Intel");
            dal.DeleteData("Delete  from Systems");

            dal.UpdateData("Update configuration set PlayersInLastSystem = 0, LastOrginID = 1, SupplyUnitsPrice= 1500, GameStart = @param0", new System.Collections.Generic.List<object>() { DateTime.Now });
            dal.DeleteData("Drop table Systems");
            if (dal.DataSource == DataSources.MSSQL)
                dal.DeleteData(MsSqlCreateTableSystems);
            else
                dal.DeleteData(MySqlCreateTableSystems);
            CreateGame();
        }
    };
}